import { get, post } from '@/utils/request'
import type { StatisticsResponse } from '@/types/api'

// 统计相关API
export const statisticsApi = {
  // 获取平台总体统计
  getPlatformStats: (): Promise<StatisticsResponse> => {
    return get<StatisticsResponse>('/statistics/platform')
  },

  // 获取项目统计
  getProjectStats: (params?: any): Promise<any> => {
    return get('/statistics/projects', params)
  },

  // 获取申请统计
  getApplicationStats: (params?: any): Promise<any> => {
    return get('/statistics/applications', params)
  },

  // 获取匹配统计
  getMatchStats: (params?: any): Promise<any> => {
    return get('/statistics/matches', params)
  },

  // 获取用户统计
  getUserStats: (params?: any): Promise<any> => {
    return get('/statistics/users', params)
  },

  // 获取学科分布统计
  getDisciplineStats: (params?: any): Promise<any> => {
    return get('/statistics/disciplines', params)
  },

  // 获取时间趋势统计
  getTrendStats: (params: { type: 'daily' | 'weekly' | 'monthly'; startDate: string; endDate: string }): Promise<any> => {
    return get('/statistics/trends', params)
  },

  // 获取企业统计
  getEnterpriseStats: (params?: any): Promise<any> => {
    return get('/statistics/enterprises', params)
  },

  // 获取学院统计
  getCollegeStats: (params?: any): Promise<any> => {
    return get('/statistics/colleges', params)
  },

  // 导出统计数据
  exportStatistics: (params: { type: string; format: 'excel' | 'csv' | 'pdf' }): Promise<void> => {
    return get('/statistics/export', params, { responseType: 'blob' })
  },

  // 生成统计报告
  generateReport: (params: { type: string; startDate: string; endDate: string }): Promise<any> => {
    return post('/statistics/reports', params)
  },

  // 获取报告列表
  getReportList: (params?: any): Promise<any> => {
    return get('/statistics/reports', params)
  },

  // 下载报告
  downloadReport: (id: string): Promise<void> => {
    return get(`/statistics/reports/${id}/download`, {}, { responseType: 'blob' })
  }
}

// 图表数据API
export const chartApi = {
  // 获取柱状图数据
  getBarChartData: (params: { type: string; dimensions: string[] }): Promise<any> => {
    return get('/charts/bar', params)
  },

  // 获取折线图数据
  getLineChartData: (params: { type: string; timeRange: string }): Promise<any> => {
    return get('/charts/line', params)
  },

  // 获取饼图数据
  getPieChartData: (params: { type: string; category: string }): Promise<any> => {
    return get('/charts/pie', params)
  },

  // 获取雷达图数据
  getRadarChartData: (params: { type: string; indicators: string[] }): Promise<any> => {
    return get('/charts/radar', params)
  },

  // 获取热力图数据
  getHeatmapData: (params: { type: string; xAxis: string; yAxis: string }): Promise<any> => {
    return get('/charts/heatmap', params)
  }
}

// 实时数据API
export const realtimeApi = {
  // 获取实时统计
  getRealtimeStats: (): Promise<any> => {
    return get('/realtime/stats')
  },

  // 获取在线用户数
  getOnlineUsers: (): Promise<any> => {
    return get('/realtime/online-users')
  },

  // 获取系统状态
  getSystemStatus: (): Promise<any> => {
    return get('/realtime/system-status')
  },

  // 获取API调用统计
  getApiCallStats: (): Promise<any> => {
    return get('/realtime/api-calls')
  }
}
